﻿<%@ Page Language="C#" MasterPageFile="~/Master/Site.Master" AutoEventWireup="true"
    CodeBehind="kptj.aspx.cs" Inherits="聚欣订单分析.kptj" Title="聚欣订单分析" %>

<%@ Register Assembly="DevExpress.Web.v18.1, Version=18.1.7.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a"
    Namespace="DevExpress.Web" TagPrefix="dx" %>


<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <script type="text/javascript">
        var xz = 0;
        function OnGridSelectionChanged() {
            xz = 1;
            grid.GetSelectedFieldValues('ID', OnGridSelectionComplete);
        }
        function OnGridSelectionComplete(values) {
            for (var i = 0; i < values.length - 1; i++) {
                grid.SelectRowsByKey(values[i], false);
            }
        }
        function tjyz(s, e) {
            if (xz == 1) {
                var rq = deHKRQ.GetDate();
                var je = seHKJE.GetValue();
                if (rq == null) {
                    alert("开票日期不能为空！");
                    e.processOnServer = false;
                }
                else if (je <= 0) {
                    alert('开票金额必须大于0！');
                    e.processOnServer = false;
                }
                else if (!window.confirm("确定提交？")) {
                    e.processOnServer = false;
                }
            }
            else {
                alert("请选择记录！");
                e.processOnServer = false;
            }
        }
    </script>

</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="CPH_NAV" runat="server">
    <h2>开票提交</h2>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="CPH_Contents" runat="server">
    <div class="content-page">
        <div class="content">
            <div class="am-g">
                <!-- Row start -->
                <div class="card-box">
                    <table>
                        <tr>
                            <td>
                                <dx:ASPxButton ID="btnExcel" runat="server" Text="导出Excel" OnClick="btnExcel_Click">
                                    <Image Url="~/images/ICON/Excel.gif">
                                    </Image>
                                </dx:ASPxButton>
                            </td>
                        </tr>
                    </table>
                    <dx:ASPxGridView ID="ASPxGridView1" ClientInstanceName="grid" runat="server" Width="100%"
                        AutoGenerateColumns="False" DataSourceID="SqlDataSource1" KeyFieldName="ID">
                        <ClientSideEvents SelectionChanged="function(s, e) {OnGridSelectionChanged()}" />
                        <Columns>
                            <dx:GridViewCommandColumn Caption="操作" VisibleIndex="0" Width="50px" ShowSelectButton="true">
                            </dx:GridViewCommandColumn>
                            <dx:GridViewDataTextColumn FieldName="ID" VisibleIndex="1" Visible="false">
                            </dx:GridViewDataTextColumn>
                            <dx:GridViewDataTextColumn FieldName="年份" VisibleIndex="1" Width="70px">
                                <EditFormSettings Visible="False" />
                            </dx:GridViewDataTextColumn>
                            <dx:GridViewDataTextColumn FieldName="订单号" VisibleIndex="2" Width="90px">
                                <EditFormSettings Visible="False" />
                            </dx:GridViewDataTextColumn>
                            <dx:GridViewDataTextColumn FieldName="省" VisibleIndex="3" Width="70px">
                                <EditFormSettings Visible="False" />
                            </dx:GridViewDataTextColumn>
                            <dx:GridViewDataTextColumn FieldName="地市" VisibleIndex="4" Width="70px">
                                <EditFormSettings Visible="False" />
                            </dx:GridViewDataTextColumn>
                            <dx:GridViewDataTextColumn FieldName="运营商" VisibleIndex="4" Width="250px">
                                <EditFormSettings Visible="False" />
                            </dx:GridViewDataTextColumn>
                            <dx:GridViewDataTextColumn FieldName="项目" VisibleIndex="4" Width="250px">
                                <EditFormSettings Visible="False" />
                            </dx:GridViewDataTextColumn>
                            <dx:GridViewDataTextColumn FieldName="订单金额" VisibleIndex="5">
                                <EditFormSettings Visible="False" />
                            </dx:GridViewDataTextColumn>
                            <dx:GridViewDataDateColumn FieldName="订单日期" VisibleIndex="6">
                                <EditFormSettings Visible="False" />
                            </dx:GridViewDataDateColumn>
                            <dx:GridViewDataComboBoxColumn FieldName="开票" VisibleIndex="14" Width="60px">
                                <EditFormSettings Visible="False" />
                                <PropertiesComboBox>
                                    <Items>
                                        <dx:ListEditItem Text="已开" Value="已开" />
                                        <dx:ListEditItem Text="未开" Value="未开" />
                                    </Items>
                                </PropertiesComboBox>
                            </dx:GridViewDataComboBoxColumn>
                            <dx:GridViewDataSpinEditColumn FieldName="开票金额" VisibleIndex="6">
                                <PropertiesSpinEdit DecimalPlaces="2">
                                </PropertiesSpinEdit>
                            </dx:GridViewDataSpinEditColumn>
                            <dx:GridViewDataTextColumn FieldName="未开金额" VisibleIndex="6" Width="90px">
                                <EditFormSettings Visible="False" />
                            </dx:GridViewDataTextColumn>
                            <dx:GridViewDataDateColumn FieldName="开票日期" VisibleIndex="6">
                            </dx:GridViewDataDateColumn>
                            <dx:GridViewDataTextColumn FieldName="状态" VisibleIndex="18">
                                <EditFormSettings Visible="False" />
                            </dx:GridViewDataTextColumn>
                            <dx:GridViewDataMemoColumn FieldName="开票备注" VisibleIndex="19">
                                <EditFormSettings ColumnSpan="4" RowSpan="4" />
                            </dx:GridViewDataMemoColumn>
                        </Columns>
                        <Settings ShowGroupPanel="true" ShowHorizontalScrollBar="true" ShowFilterRow="true"
                            ShowFilterRowMenu="true" ShowFilterBar="Visible" ShowFooter="True" />
                        <SettingsPager PageSize="30">
                        </SettingsPager>
                        <SettingsEditing Mode="PopupEditForm" PopupEditFormVerticalAlign="WindowCenter" PopupEditFormHorizontalAlign="WindowCenter"
                            PopupEditFormWidth="600px" />
                    </dx:ASPxGridView>
                    <table>
                        <tr>
                            <td>开票日期：
                            </td>
                            <td>
                                <dx:ASPxDateEdit ID="deHKRQ" runat="server" ClientInstanceName="deHKRQ" Width="100px"
                                    DisplayFormatString="yyyy-MM-dd">
                                </dx:ASPxDateEdit>
                            </td>
                            <td>开票金额：
                            </td>
                            <td>
                                <dx:ASPxSpinEdit ID="seHKJE" runat="server" Height="21px" ClientInstanceName="seHKJE"
                                    Number="0" Width="120px" DecimalPlaces="2">
                                </dx:ASPxSpinEdit>
                            </td>
                        </tr>
                        <tr>
                            <td>备注：
                            </td>
                            <td colspan="3">
                                <dx:ASPxMemo ID="ASPxMemo1" runat="server" Height="71px" Width="100%">
                                </dx:ASPxMemo>
                            </td>
                            <td valign="bottom">
                                <dx:ASPxButton ID="btnUpload" runat="server" Text=" 提 交 " OnClick="btnUpload_Click">
                                    <Image Url="~/images/ICON/accept.png">
                                    </Image>
                                    <ClientSideEvents Click="function(s, e) {
                       tjyz(s,e)
                    }" />
                                </dx:ASPxButton>
                            </td>
                        </tr>
                    </table>
                </div>
            </div>
            <!-- Row end -->
        </div>
    </div>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:JXDDConnectionString %>"
        SelectCommand="SELECT *,(ISNULL(订单金额,0)-ISNULL(开票金额,0)) as 未开金额,(SELECT TOP 1 BZ FROM tbl_KPSH WHERE   DDID = tbl_DDB.ID and zt<>'0'  ORDER BY ID desc) AS 开票备注 FROM [tbl_DDB] WHERE [开票] = '未开' or (ISNULL(订单金额,0)-ISNULL(开票金额,0))>0"
        UpdateCommand="update tbl_DDB set 开票='已开',开票日期=@开票日期,开票金额=@开票金额,备注=@备注,状态='开票待审' where ID=@ID">
        <UpdateParameters>
            <asp:Parameter Name="ID" />
            <asp:Parameter Name="开票日期" />
            <asp:Parameter Name="开票金额" />
            <asp:Parameter Name="备注" />
        </UpdateParameters>
    </asp:SqlDataSource>
    <dx:ASPxGridViewExporter ID="ASPxGridViewExporter1" GridViewID="ASPxGridView1" runat="server">
    </dx:ASPxGridViewExporter>
</asp:Content>
